#ifndef TEXTEDITOR_H
#define TEXTEDITOR_H

#include <QPlainTextEdit>
#include "common.h"

class Completer;

class TextEditor : public QPlainTextEdit
{
    Q_OBJECT
public:
    explicit TextEditor(QWidget *parent = 0);
    void setCompleter( Completer * c );
    void resetCompletter();
    Completer * completer() const { return c; }
    void updateHighlighting();
    void parseText();
    void lineNumberAreaPaintEvent( QPaintEvent * e );
    int lineNumberAreaWidth();

    void setWordWrap( bool wrap );
    bool WordWrap() { return wordWrap; }
    void setIndent( bool indent );

    QColor getFontColor() const { return textColor; }
    QColor getBackgroundColor() const { return bgColor; }
    void setBackgroungColor( QColor c = TEXT_EDITOR_BACKGROUND_COLOR );
    void setFontColor( QColor c = TEXT_EDITOR_FONT_COLOR );

protected:
    void keyPressEvent( QKeyEvent * e );
    void focusInEvent( QFocusEvent * e );
    void resizeEvent( QResizeEvent * e );

private slots:
    void insertCompletion( const QString & completion );
    void updateLineNumberAreaWidth(int newBlockCount);
    void updateLineNumberArea( const QRect & rect, int dy );

private:
    QString textUnderCursor() const;


private:
    Completer * c;
    QWidget * lineNumberArea;
    QColor bgColor;
    QColor textColor;
    bool wordWrap;
    
signals:
    void sgnParse( QString line );
    void sgnReloadModel();
    
public slots:
    
};

#endif // TEXTEDITOR_H
